﻿//生成播放列表的数据
function getPlayList(jsonData, txtData) {
    var foreastTimes = ["000", "024", "048", "072", "096", "120", "144", "168"];
    var modelA = $("#modelDiv ul").find("a.hov").eq(0);
    var stationA = $("#stationDiv ul").find("a.hov").eq(0);
    var fileTypeA = $("#fileTypeDiv ul").find("a.hov").eq(0);
    var modelType = "";    //模式类型
    var productName = "";      //产品名称
    var station = "";      //站点信息
    var fileType = "";      //文件类型
    var mapContainer = $("#mapContainer");     //显示表格的容器
    var mapContainerHtml = "<img id='img' src='../Content/themes/default/images/wutupian.jpg' border='0' />";
    //没有数据
    if (txtData.length <= 0) {
        mapContainer.html(mapContainerHtml);
        return;
    }
    var tableContainerHtml = '<div class="data-list">';
    tableContainerHtml += '<table class="data-table display">';
    var thead = '<thead>';
    var tbody = '<tbody><tr><td colspan="17" align="center"><img id="img" src="../Content/themes/default/images/wutupian.jpg" border="0" /></td></tr>';
    var tr = '<tr>';
    tr += '<th rowspan="2">预报时间</th>';
    tr += '<th rowspan="2">预报时长</th>';
    tr += '<th colspan="2">SO<sub>2</sub>24小时平均</th>';
    tr += '<th colspan="2">NO<sub>2</sub>24小时平均</th>';
    tr += '<th colspan="2">PM<sub>10</sub>24小时平均</th>';
    tr += '<th colspan="2">CO24小时平均</th>';
    tr += '<th colspan="2">O<sub>3</sub>最大1小时平均</th>';
    tr += '<th colspan="2">O<sub>3</sub>最大8小时滑动平均</th>';
    tr += '<th colspan="2">PM<sub>2.5</sub>24小时平均</th>';
    tr += '<th rowspan="2">AQI</th>';
    tr += '<th rowspan="2">首要污染物</th>';
    tr += '</tr>';
    thead += tr;
    tr = '<tr>';
    for (var i = 0; i < 7; i++) {
        tr += '<th>浓度</th><th>分指数</th>';
    }
    tr += '</tr>';
    thead += tr;
    thead += '</thead>';
    tableContainerHtml += thead;

    if (modelA.length > 0) {
        modelType = modelA.attr("value");
    }
    if (stationA.length > 0) {
        station = stationA.attr("value");
    }
    if (fileTypeA.length > 0) {
        fileType = fileTypeA.attr("value");
    }

    if (station === "") {
        productName = fileType;
    }
    else {
        productName = fileType + "-" + station;
    }

    //生成tbody内容
    var data = false;
    for (var i = 0; i < txtData.length; i++) {
        var txtDataItem = txtData[i];
        if (txtDataItem.ModeType === modelType && txtDataItem.ProductName === productName) {
            if (!data) {
                tbody = '<tbody>';
                data = true;
            }
            tr = '<tr>';
            tr += '<td>' + formatDate(GetTimeFromJsonString(txtDataItem.ForTime), "YYYY/MM/DD") + '</td>';
            tr += '<td>' + foreastTimes[i] + '</td>';
            tr += '<td>' + txtDataItem.SO2Concentration + '</td>';
            tr += '<td>' + txtDataItem.SO2Subindex + '</td>';
            tr += '<td>' + txtDataItem.NO2Concentration + '</td>';
            tr += '<td>' + txtDataItem.NO2Subindex + '</td>';
            tr += '<td>' + txtDataItem.PM10Concentration + '</td>';
            tr += '<td>' + txtDataItem.PM10Subindex + '</td>';
            tr += '<td>' + txtDataItem.COConcentration.toFixed(1) + '</td>';
            tr += '<td>' + txtDataItem.COSubindex + '</td>';
            tr += '<td>' + txtDataItem.O3_1Concentration + '</td>';
            tr += '<td>' + txtDataItem.O3_1Subindex + '</td>';
            tr += '<td>' + txtDataItem.O3_8Concentration + '</td>';
            tr += '<td>' + txtDataItem.O3_8Subindex + '</td>';
            tr += '<td>' + txtDataItem.PM25Concentration + '</td>';
            tr += '<td>' + txtDataItem.PM25Subindex + '</td>';
            tr += '<td>' + txtDataItem.AQI + '</td>';
            tr += '<td>' + ENToCNForPrimaryPollutant(txtDataItem.PrimaryPollutant) + '</td>';
            tr += '</tr>';
            tbody += tr;
        }
    }
    tbody += '</tbody>';
    tableContainerHtml += tbody;
    tableContainerHtml += '</table>';
    tableContainerHtml += ' </div>';

    mapContainer.html("");
    mapContainer.html(tableContainerHtml);
}

//首要污染物英文转中文
function ENToCNForPrimaryPollutant(en) {
    en = en.replace("SO2", "二氧化硫");
    en = en.replace("CO", "一氧化碳");
    en = en.replace("NO2", "二氧化氮");
    en = en.replace("O3_8h", "臭氧8小时");
    en = en.replace("O3", "臭氧1小时");
    en = en.replace("PM2.5_24h", "细颗粒物(PM2.5)");
    en = en.replace("PM10_24h", "颗粒物(PM10)");
    en = en.replace("-", "无首要污染物");
    en = en.replace("、", "，");
    return en;
}

//页面加载完成后的事件
function Start(jsonData, txtData) {
    getPlayList(jsonData, txtData);

    //条件选择点击事件
    $("#fileTypeDiv,#stationDiv,#modelDiv").find("li").click(function () {
        $(this).parent().find("a").removeClass("hov");
        $(this).find("a").addClass("hov");
        getPlayList(jsonData, txtData);
    });
}